package com.four.controller;

import com.four.pojo.Product;
import com.four.pojo.Records;
import com.four.pojo.Recordscr;
import com.four.service.IRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author 王森
 * @create 2021-10-24 19:10
 */
 @Controller
public class RecordsController {

    @Autowired
    @Qualifier("recordsService")
    private IRecordsService iRecordsService;


    @RequestMapping("/recordsAll")
    private String recordscrAll(Model model){
        List<Recordscr> list= iRecordsService.recordscrAll();
        model.addAttribute("list",list);
        return "expenses_Record.jsp";
    }



    @RequestMapping("/recordsAll2")
    private String recordsAll2(Model model){
        List<Product> list= iRecordsService.recordsAll();
        model.addAttribute("list",list);
        return "Expenses.jsp";
    }


    //消耗品的添加
    @RequestMapping("/addRecords")
    private String addRecords(Product product,Recordscr recordscr){
        Date date = new Date();
        product.setPtime(date);
        iRecordsService.addRecords(product);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        recordscr.setPtime(sdf.format(date));
        iRecordsService.addRecordsRu(recordscr);

        return "redirect:/recordsAll2";
    }




        @RequestMapping("recordsAllBy")
    public String recordsAllBy(Recordscr recordscr,Model model){
        List<Recordscr> list= iRecordsService.recordsAllBy(recordscr);
            System.out.println(recordscr.getPtime());
        model.addAttribute("list",list);
        return "expenses_Record.jsp";
    }






    @RequestMapping("recordsBY")
    private String recordsBY(Model model,int pid){
        Product product= iRecordsService.recordsBY(pid);
        model.addAttribute("product",product);
        System.out.println(1111);
        return "sign_In.jsp";
    }



    @RequestMapping("upRecords")
    private String uprecords(Product product,Recordscr recordscr){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        Date date = new Date();
        recordscr.setPtime(sdf.format(date));
        iRecordsService.addRecordsRu(recordscr);
        System.out.println(product.getIfrecord());
        iRecordsService.uprecords(product);
        System.out.println(product);
        return "redirect:recordsAll2";
    }


    @RequestMapping("recordsBY2")
    private String recordsBY2(Model model,int pid){
        Product product= iRecordsService.recordsBY(pid);
        model.addAttribute("product",product);
        System.out.println(222);
        return "sign_Out.jsp";
    }


    @RequestMapping("OutRecords")
    private String OutRecords(Product product,Recordscr recordscr){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        Date date = new Date();
        recordscr.setPtime(sdf.format(date));
        iRecordsService.addRecordsChu(recordscr);
        System.out.println(recordscr.getIfrecord());
        iRecordsService.OutRecords(product);
        System.out.println(product);
        return "redirect:recordsAll2";
    }


}
